package day_2022_4_to_7.day48;

/**
 * @author haomin
 * @date 2022/07/09 10:44
 **/
public class Day48_1_FindMaxByLeftAndRightArr {

    public static void main(String[] args) {
        int[] arr = {2,7,3,1,1};
        System.out.println(findMaxGap(arr,5));
    }
    public static int findMaxGap(int[] A, int n) {
        int[] arr = new int[n];
        for(int i = 1;i < n;i++){
            int leftMax = getMax(A,0,i);
            int rightMax = getMax(A,i,n);

            int max = leftMax - rightMax;
            arr[i] = Math.abs(max);
        }
        int max = getMax(arr,1,n);
        return max;
    }

    private static int getMax(int[] a, int left, int right) {
        int max = Integer.MIN_VALUE;
        for (int i = left;i < right;i++){
            if (max < a[i]) max = a[i];
        }
        return max;
    }
}